
package org.geometerplus.android.fbreader;

import android.graphics.ColorMatrixColorFilter;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import org.geometerplus.zlibrary.core.resources.ZLResource;

import org.geometerplus.zlibrary.text.view.ZLTextView;
import org.geometerplus.zlibrary.text.view.ZLTextWordCursor;

import org.geometerplus.zlibrary.ui.android.R;

import org.geometerplus.fbreader.bookmodel.TOCTree;
import org.geometerplus.fbreader.fbreader.ActionCode;
import org.geometerplus.fbreader.fbreader.FBReaderApp;

final class NavigationPopupTop extends PopupPanel {
	final static String ID = "NavigationPopupTop";

	private ImageButton bookmark;
	private Boolean markonFlag = false;
	public void setMarkonFlag(Boolean markonFlag) {
		this.markonFlag = markonFlag;
	}

	NavigationPopupTop(FBReaderApp fbReader) {
		super(fbReader);
	}

	public void runNavigation() {
		if (myWindow == null || myWindow.getVisibility() == View.GONE) {
			Application.showPopup(ID);
		}else{
			Application.hidePopup(ID);
			getReader().getViewWidget().reset();
			getReader().getViewWidget().repaint();
		}
	}

	@Override
	public String getId() {
		return ID;
	}

	@Override
	protected void show_() {
		super.show_();
		if (myWindow != null) {
		}
	}

	@Override
	public void createControlPanel(FBReader activity, RelativeLayout root) {
		if (myWindow != null && activity == myWindow.getActivity()) {
			return;
		}

		myWindow = new PopupWindow(activity, root, PopupWindow.Location.Top, true);

		final View layout = activity.getLayoutInflater().inflate(R.layout.navigate_top, myWindow, false);

		ImageButton backtoshlf = (ImageButton)layout.findViewById(R.id.backtoshlf);
 		ImageButton bookindex = (ImageButton)layout.findViewById(R.id.bookindex);
 		bookmark = (ImageButton)layout.findViewById(R.id.bookmark);
 		final float[] BT_SELECTED = new float[] {2, 0, 0, 0, 2,   
			      0, 2, 0, 0, 2,   
			      0, 0, 2, 0, 2,   
			      0, 0, 0, 1, 0};
 		bookmark.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
		bookmark.setBackgroundDrawable(bookmark.getBackground());
 		
 		activity.addImageButton(backtoshlf, ActionCode.SHOW_LIBRARY);
 		activity.addImageButton(bookindex, ActionCode.SHOW_TOC);
 		activity.addImageButton(bookmark, ActionCode.SHOW_BOOKMARKS);
 		
		myWindow.addView(layout);
	}

	@Override
	protected void update() {
		// TODO Auto-generated method stub
		if(null != bookmark){
			if(markonFlag){
				bookmark.setBackgroundResource(R.drawable.icon_mark_on);
			}
			else {
				bookmark.setBackgroundResource(R.drawable.icon_bookmark);
			}
			
			final float[] BT_SELECTED = new float[] {2, 0, 0, 0, 2,   
				      0, 2, 0, 0, 2,   
				      0, 0, 2, 0, 2,   
				      0, 0, 0, 1, 0};
			//bookmark.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
			//bookmark.setBackgroundDrawable(bookmark.getBackground());
		}
		
	}

	
}
